package com.albon.alarm;

import com.albon.sportsalarm.R;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Vibrator;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

public class AlarmOffTimeList extends Activity {
	private final String TAG = "AlarmOffTimeList";
	private  String[] timer_off_time_name_array =  {};
	private ListView listView = null;
	Button ok = null;
	Button cancel = null;
	
	private int requestCode = 0;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.alarm_auto_time_off);
		setTitle(getResources().getString(R.string.set_alarm_off_time));
		timer_off_time_name_array =  getResources().getStringArray(R.array.auto_alarm_off_time_name_value);
		requestCode = getIntent().getIntExtra("alarm_off_time", 0);		
		
		
		ArrayAdapter<String> arrayAdater = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_single_choice, timer_off_time_name_array);
		
         listView = (ListView)findViewById(R.id.select_time);
         listView.setAdapter(arrayAdater);
         listView.setItemChecked(requestCode, true);
         listView.setOnItemClickListener(vibrateOnItemClickListener);
        
        ok = (Button)findViewById(R.id.okBtn);
	    ok.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = getIntent();
				intent.putExtra("alarm_off_time", requestCode);
				setResult(RESULT_OK, intent);
				
				finish();
				
			}
		});
	    cancel = (Button)findViewById(R.id.cancelBtn);
	    cancel.setOnClickListener(new OnClickListener() {
	    	
	    	@Override
	    	public void onClick(View v) {
	    		// TODO Auto-generated method stub
	    		
	    		finish();
	    	}
	    });
	    
	    
	}
	@Override
	protected void onUserLeaveHint() {
		// TODO Auto-generated method stub
		super.onUserLeaveHint();
		Log.e(TAG,"===KEYCODE_HOMEKEY===");
		
	}
	
	@Override
	public boolean onKeyUp(int keyCode, KeyEvent event) {
		boolean check = true;
		//Log.e(TAG,"keyCode = "+keyCode+" //// event = "+event);
		switch(keyCode)
		{
		case KeyEvent.KEYCODE_BACK : 
			Log.e(TAG,"===KEYCODE_BACK===");
			
			break;
		}
		return super.onKeyUp(keyCode, event);
	}
	
	AdapterView.OnItemClickListener vibrateOnItemClickListener = new AdapterView.OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView parent, View view, int position,
				long id) {
			// TODO Auto-generated method stub
			
			Log.d(TAG, "position : "+position);
			requestCode = position;
			
		}
	};
	
}
